﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Business.Entities;
using Business.Logic;


namespace UI.Desktop
{
    public partial class PersonasD : MdiFormPadre
    {
        private List<Plan> _ListaPlanes;

        public List<Plan> ListaPlanes
        {
            get { return _ListaPlanes; }
            set { _ListaPlanes = value; }
        }

        public PersonasD()
        {
            InitializeComponent();
            this.dgvPersona.AutoGenerateColumns = false;
        }
        
        #region Eventos

        private void tsbNuevo_Click(object sender, EventArgs e)
        {
            PersonasDesktop AlumnoDesk = new PersonasDesktop(PersonasDesktop.ModoForm.Alta, ListaPlanes);
            AlumnoDesk.Text = "Crear nueva persona";
            AlumnoDesk.ShowDialog();
            this.Listar();
        }

        private void tsbConsultar_Click(object sender, EventArgs e)
        {
            int i = ((Persona)this.dgvPersona.SelectedRows[0].DataBoundItem).ID;
            PersonasDesktop AlumnoDesk = new PersonasDesktop(i, ApplicationForm.ModoForm.Consulta, ListaPlanes);
            AlumnoDesk.Text = "Consultar persona";
            AlumnoDesk.ShowDialog();
            this.Listar();
        }

        private void tsbEditar_Click(object sender, EventArgs e)
        {
            int i = ((Persona)this.dgvPersona.SelectedRows[0].DataBoundItem).ID;
            PersonasDesktop AlumnoDesk = new PersonasDesktop(i, ApplicationForm.ModoForm.Modifica, ListaPlanes);
            AlumnoDesk.Text = "Editar persona";
            AlumnoDesk.ShowDialog();
            this.Listar();
        }

        private void tsbEliminar_Click(object sender, EventArgs e)
        {
            int i = ((Persona)this.dgvPersona.SelectedRows[0].DataBoundItem).ID;
            PersonasDesktop AlumnoDesk = new PersonasDesktop(i, ApplicationForm.ModoForm.Baja, ListaPlanes);
            AlumnoDesk.Text = "Eliminar persona";
            AlumnoDesk.ShowDialog();
            this.Listar();
        }

        private void btnActualizar_Click(object sender, EventArgs e)
        {
            this.Listar();
        }

        private void btnSalir_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void PersonasD_Load(object sender, EventArgs e)
        {
            this.Listar();
            PlanesLogic Plogic = new PlanesLogic();
            ListaPlanes = Plogic.GetAll();
        }
        
        #endregion


        #region Métodos

        public void Listar()
        {
            try
            {
                PersonaLogic perLog = new PersonaLogic();
                this.dgvPersona.DataSource = null;
                this.dgvPersona.DataSource = perLog.GetAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        #endregion

    }
}
